load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("@rules_license//rules:license.bzl", "license")
load("@rules_python//python:defs.bzl", "py_binary")

package(default_applicable_licenses = [":license"])

license(
    name = "license",
    license_kinds = ["@rules_license//licenses/spdx:BSD-3-Clause"],
    license_text = "LICENSE",
    visibility = ["//visibility:public"],
)

# NOTE: This is one big library because some of the headers have complex circular dependencies.
cc_library(
    name = "proxygen",
    srcs = glob(
        ["proxygen/lib/**/*.cpp"],
        exclude = [
            # This library doesn't compile and is not included in the CMakeLists.txt.
            "proxygen/lib/dns/**",
            # This is a binary tool, not part of the lib.
            "proxygen/lib/http/codec/compress/experimental/interop/**",
            # This is a binary tool, not part of the lib.
            "proxygen/lib/http/codec/compress/experimental/simulator/**",
            # The stats lib depends on fb303 which is heavy-weight and not yet in the BCR.
            "proxygen/lib/stats/**",
            # Disabled because it depends on the stats lib.
            "proxygen/lib/http/stats/**",
            # Disabled because it depends on the stats lib.
            "proxygen/lib/ssl/ThreadLocalSSLStats.cpp",
            "proxygen/lib/**/test/**",
        ],
    ) + [
        # Generated by :gen_http_common_headers_srcs
        "proxygen/lib/http/HTTPCommonHeaders.cpp",
        # Generated by :gen_trace_event_constants_srcs
        "proxygen/lib/utils/TraceEventType.cpp",
        # Generated by :gen_trace_event_constants_srcs
        "proxygen/lib/utils/TraceFieldType.cpp",
    ],
    hdrs = glob(
        ["proxygen/lib/**/*.h"],
        exclude = [
            # This library doesn't compile and is not included in the CMakeLists.txt.
            "proxygen/lib/dns/**",
            "proxygen/lib/utils/perfect_hash_table_template.h",
            # The stats lib depends on fb303 which is heavy-weight and not yet in the BCR.
            "proxygen/lib/stats/**",
            # Disabled because it depends on the stats lib.
            "proxygen/lib/http/stats/**",
            # Disabled because it depends on the stats lib.
            "proxygen/lib/ssl/ThreadLocalSSLStats.h",
            "proxygen/lib/**/test/**",
        ],
    ) + [
        # Generated by :gen_http_common_headers_srcs:
        "proxygen/lib/http/HTTPCommonHeaders.h",
        # Generated by :gen_trace_event_constants_srcs
        "proxygen/lib/utils/TraceEventType.h",
        # Generated by :gen_trace_event_constants_srcs
        "proxygen/lib/utils/TraceFieldType.h",
    ],
    includes = ["."],
    # Silence #pragma warnings about deprecated boost bind usage.
    local_defines = ["BOOST_BIND_GLOBAL_PLACEHOLDERS"],
    visibility = ["//visibility:public"],
    deps = [
        ":external_http_parser",
        ":gen_http_common_headers_srcs",
        ":gen_trace_event_constants_srcs",
        "@boost.algorithm",
        "@boost.bind",
        "@boost.filesystem",
        "@boost.iostreams",
        "@boost.lexical_cast",
        "@boost.thread",
        "@boost.variant",
        "@fizz",
        "@fmt",
        "@folly//folly:base64",
        "@folly//folly:cancellation_token",
        "@folly//folly:conv",
        "@folly//folly:cpp_attributes",
        "@folly//folly:exception_wrapper",
        "@folly//folly:expected",
        "@folly//folly:fbstring",
        "@folly//folly:file_util",
        "@folly//folly:format",
        "@folly//folly:function",
        "@folly//folly:indestructible",
        "@folly//folly:intrusive_list",
        "@folly//folly:memory",
        "@folly//folly:network_address",
        "@folly//folly:observer_container",
        "@folly//folly:optional",
        "@folly//folly:overload",
        "@folly//folly:portability",
        "@folly//folly:random",
        "@folly//folly:range",
        "@folly//folly:scope_guard",
        "@folly//folly:singleton",
        "@folly//folly:singleton_thread_local",
        "@folly//folly:small_vector",
        "@folly//folly:string",
        "@folly//folly:synchronized",
        "@folly//folly:thread_local",
        "@folly//folly:try",
        "@folly//folly:utility",
        "@folly//folly/compression",
        "@folly//folly/container:evicting_cache_map",
        "@folly//folly/container:f14_hash",
        "@folly//folly/container:foreach",
        "@folly//folly/container:reserve",
        "@folly//folly/experimental/io:io_uring_backend",
        "@folly//folly/experimental/symbolizer",
        "@folly//folly/futures:core",
        "@folly//folly/hash",
        "@folly//folly/io:iobuf",
        "@folly//folly/io:socket_option_map",
        "@folly//folly/io/async:async_base",
        "@folly//folly/io/async:async_socket",
        "@folly//folly/io/async:async_socket_exception",
        "@folly//folly/io/async:async_ssl_socket",
        "@folly//folly/io/async:async_transport",
        "@folly//folly/io/async:async_udp_socket",
        "@folly//folly/io/async:delayed_destruction",
        "@folly//folly/io/async:destructor_check",
        "@folly//folly/io/async:event_base_manager",
        "@folly//folly/io/async:server_socket",
        "@folly//folly/io/async:ssl_context",
        "@folly//folly/json:dynamic",
        "@folly//folly/lang:assume",
        "@folly//folly/lang:bits",
        "@folly//folly/lang:exception",
        "@folly//folly/logging",
        "@folly//folly/portability:gflags",
        "@folly//folly/portability:openssl",
        "@folly//folly/portability:sockets",
        "@folly//folly/portability:stdlib",
        "@folly//folly/portability:sys_resource",
        "@folly//folly/portability:time",
        "@folly//folly/portability:unistd",
        "@folly//folly/portability:windows",
        "@folly//folly/ssl:openssl_hash",
        "@folly//folly/ssl:ssl_session",
        "@folly//folly/synchronization:rcu",
        "@folly//folly/tracing:scoped_trace_section",
        "@gflags",
        "@glog",
        "@mvfst//:quic",
        "@openssl//:ssl",
        "@wangle//:acceptor",
        "@wangle//:client_persistence",
        "@wangle//:ssl",
        "@zlib",
        "@zstd",
    ],
)

cc_library(
    name = "httpserver",
    srcs = glob(
        ["proxygen/httpserver/**/*.cpp"],
        exclude = [
            "proxygen/httpserver/samples/**",
            "proxygen/httpserver/**/tests/**",
        ],
    ),
    hdrs = glob(
        ["proxygen/httpserver/**/*.h"],
        exclude = [
            "proxygen/httpserver/samples/**",
            "proxygen/httpserver/Mocks.h",
        ],
    ),
    includes = ["."],
    visibility = ["//visibility:public"],
    deps = [
        ":proxygen",
        "@boost.thread",
        "@folly//folly:exception_string",
        "@folly//folly:expected",
        "@folly//folly:function",
        "@folly//folly:network_address",
        "@folly//folly:range",
        "@folly//folly:scope_guard",
        "@folly//folly/executors:io_thread_pool_executor",
        "@folly//folly/executors/thread_factory:named_thread_factory",
        "@folly//folly/io/async:async_signal_handler",
        "@folly//folly/io/async:event_base_manager",
        "@folly//folly/io/async:server_socket",
        "@folly//folly/io/async:ssl_context",
        "@folly//folly/system:thread_name",
        "@wangle//:bootstrap",
        "@wangle//:ssl",
    ],
)

cc_library(
    name = "external_http_parser",
    srcs = ["proxygen/external/http_parser/http_parser_cpp.cpp"],
    hdrs = ["proxygen/external/http_parser/http_parser.h"],
    visibility = ["//visibility:public"],
)

genrule(
    name = "gen_http_common_headers_srcs",
    srcs = [
        "proxygen/lib/http/gen_HTTPCommonHeaders.sh",
        "proxygen/lib/utils/gen_perfect_hash_table.sh",
        "proxygen/lib/utils/perfect_hash_table_template.h",
        "proxygen/lib/utils/perfect_hash_table_template.cpp.gperf",
        "proxygen/lib/http/HTTPCommonHeaders.txt",
        "LICENSE",
    ],
    outs = [
        "proxygen/lib/http/HTTPCommonHeaders.h",
        "proxygen/lib/http/HTTPCommonHeaders.cpp",
    ],
    cmd = "mkdir -p $(RULEDIR)/proxygen/lib/http && " +
          "HEADERS_LIST=$(execpath proxygen/lib/http/HTTPCommonHeaders.txt) " +
          "INSTALL_DIR=$(RULEDIR)/proxygen/lib/http " +
          "FBCODE_DIR=$$(dirname $(execpath //:LICENSE)) " +
          "OUTPUT_DIR=$(RULEDIR)/proxygen/lib/http " +
          "GPERF=$(execpath @gperf) " +
          "$(execpath proxygen/lib/http/gen_HTTPCommonHeaders.sh) " +
          "$(execpath proxygen/lib/http/HTTPCommonHeaders.txt)",
    tools = ["@gperf"],
)

py_binary(
    name = "gen_trace_event_constants",
    srcs = ["proxygen/lib/utils/gen_trace_event_constants.py"],
    visibility = ["//visibility:public"],
)

genrule(
    name = "gen_trace_event_constants_srcs",
    srcs = [
        "proxygen/lib/utils/samples/TraceEventType.txt",
        "proxygen/lib/utils/samples/TraceFieldType.txt",
    ],
    outs = [
        "proxygen/lib/utils/TraceEventType.h",
        "proxygen/lib/utils/TraceEventType.cpp",
        "proxygen/lib/utils/TraceFieldType.h",
        "proxygen/lib/utils/TraceFieldType.cpp",
    ],
    cmd = "mkdir -p $(RULEDIR)/proxygen/lib/utils && " +
          "$(execpath :gen_trace_event_constants) " +
          "--output_type=cpp " +
          "--input_files=$(execpath proxygen/lib/utils/samples/TraceEventType.txt)," +
          "$(execpath proxygen/lib/utils/samples/TraceFieldType.txt) " +
          "--output_scope=proxygen " +
          "--header_path=proxygen/lib/utils " +
          "--fbcode_dir=UNUSED " +
          "--install_dir=$(RULEDIR)/proxygen/lib/utils",
    tools = [":gen_trace_event_constants"],
)

###################################################################################################
# Samples
###################################################################################################

cc_library(
    name = "httpclient_samples_curl_lib",
    srcs = ["proxygen/httpclient/samples/curl/CurlClient.cpp"],
    hdrs = ["proxygen/httpclient/samples/curl/CurlClient.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":proxygen",
        "@folly//folly:file_util",
        "@folly//folly:string",
        "@folly//folly/io/async:ssl_context",
        "@folly//folly/io/async:ssl_options",
        "@folly//folly/portability:gflags",
    ],
)

cc_binary(
    name = "httpclient_samples_curl",
    srcs = ["proxygen/httpclient/samples/curl/CurlClientMain.cpp"],
    visibility = ["//visibility:public"],
    deps = [
        ":httpclient_samples_curl_lib",
        ":proxygen",
        "@folly//folly:network_address",
        "@folly//folly/init",
        "@folly//folly/io:socket_option_map",
        "@folly//folly/io/async:async_base",
        "@folly//folly/io/async:ssl_context",
    ],
)

cc_library(
    name = "httpclient_samples_h3_datagram",
    srcs = ["proxygen/httpclient/samples/H3Datagram/H3DatagramClient.cpp"],
    visibility = ["//visibility:public"],
    deps = [
        ":httpserver_samples_hq_lib",
        ":proxygen",
        "@folly//folly:network_address",
        "@folly//folly/init",
        "@folly//folly/io/async:async_base",
        "@folly//folly/portability:gflags",
    ],
)

cc_binary(
    name = "httpclient_samples_httperf2",
    srcs = glob([
        "proxygen/httpclient/samples/httperf2/*.cpp",
        "proxygen/httpclient/samples/httperf2/*.h",
    ]),
    visibility = ["//visibility:public"],
    deps = [
        ":httpserver_samples_hq_lib",
        ":proxygen",
        "@boost.conversion",
        "@fizz",
        "@folly//folly:file_util",
        "@folly//folly:network_address",
        "@folly//folly:random",
        "@folly//folly:string",
        "@folly//folly/init",
        "@folly//folly/io:socket_option_map",
        "@folly//folly/io/async:async_base",
        "@folly//folly/io/async:async_ssl_socket",
        "@folly//folly/json:dynamic",
        "@folly//folly/portability:gflags",
        "@folly//folly/portability:openssl",
        "@folly//folly/ssl:ssl_session",
        "@mvfst//:quic",
        "@openssl//:ssl",
    ],
)

cc_binary(
    name = "httpclient_samples_pricli",
    srcs = ["proxygen/httpclient/samples/pricli/PriCli.cpp"],
    visibility = ["//visibility:public"],
    deps = [
        ":proxygen",
        "@folly//folly:network_address",
        "@folly//folly/io:socket_option_map",
        "@folly//folly/io/async:async_base",
        "@folly//folly/io/async:ssl_context",
        "@folly//folly/io/async:ssl_options",
        "@folly//folly/portability:gflags",
    ],
)

cc_binary(
    name = "httpclient_samples_websocket",
    srcs = glob([
        "proxygen/httpclient/samples/websocket/*.cpp",
        "proxygen/httpclient/samples/websocket/*.h",
    ]),
    visibility = ["//visibility:public"],
    deps = [
        ":proxygen",
        "@folly//folly:network_address",
        "@folly//folly/init",
        "@folly//folly/io:socket_option_map",
        "@folly//folly/io/async:async_base",
    ],
)

cc_library(
    name = "httpserver_samples_echo",
    srcs = glob(
        ["proxygen/httpserver/samples/echo/**/*.cpp"],
        exclude = ["proxygen/httpserver/samples/echo/test/**"],
    ),
    hdrs = glob(["proxygen/httpserver/samples/echo/**/*.h"]),
    visibility = ["//visibility:public"],
    deps = [
        ":httpserver",
        "@folly//folly:memory",
        "@folly//folly/io/async:event_base_manager",
        "@folly//folly/portability:gflags",
        "@folly//folly/portability:unistd",
    ],
)

# Disabled because this test takes a very long time to run.
# cc_test(
#     name = "proxygen_httpserver_samples_echo_test_EchoHandlerTest",
#     size = "enormous",
#     srcs = ["proxygen/httpserver/samples/echo/test/EchoHandlerTest.cpp"],
#     deps = [
#         ":httpserver_samples_echo",
#         ":httpserver_test_lib",
#         "@folly//folly/portability:gmock",
#         "@folly//folly/portability:gtest",
#     ],
# )

cc_library(
    name = "httpserver_samples_hq_lib",
    srcs = glob(
        ["proxygen/httpserver/samples/hq/**/*.cpp"],
        exclude = [
            "proxygen/httpserver/samples/hq/**/test/**",
            "proxygen/httpserver/samples/hq/main.cpp",
        ],
    ),
    hdrs = glob(["proxygen/httpserver/samples/hq/**/*.h"]),
    visibility = ["//visibility:public"],
    deps = [
        ":httpclient_samples_curl_lib",
        ":httpserver",
        ":proxygen",
        "@boost.algorithm",
        "@boost.variant",
        "@fizz",
        "@folly//folly:conv",
        "@folly//folly:file",
        "@folly//folly:file_util",
        "@folly//folly:format",
        "@folly//folly:memory",
        "@folly//folly:network_address",
        "@folly//folly:optional",
        "@folly//folly:random",
        "@folly//folly:string",
        "@folly//folly:synchronized",
        "@folly//folly:thread_local",
        "@folly//folly/executors:global_executor",
        "@folly//folly/io:iobuf",
        "@folly//folly/io/async:async_base",
        "@folly//folly/io/async:async_socket_exception",
        "@folly//folly/io/async:async_transport",
        "@folly//folly/io/async:event_base_manager",
        "@folly//folly/io/async:scoped_event_base_thread",
        "@folly//folly/net:network_socket",
        "@gflags",
        "@glog",
        "@mvfst//:quic",
        "@wangle//:ssl",
    ],
)

cc_binary(
    name = "httpserver_samples_hq",
    srcs = ["proxygen/httpserver/samples/hq/main.cpp"],
    visibility = ["//visibility:public"],
    deps = [
        ":httpserver_samples_hq_lib",
        ":proxygen",
        "@folly//folly/init",
        "@folly//folly/portability:gflags",
    ],
)

cc_binary(
    name = "httpserver_samples_proxy",
    srcs = glob([
        "proxygen/httpserver/samples/proxy/*.cpp",
        "proxygen/httpserver/samples/proxy/*.h",
    ]),
    visibility = ["//visibility:public"],
    deps = [
        ":httpserver",
        ":proxygen",
        "@folly//folly:memory",
        "@folly//folly/io:socket_option_map",
        "@folly//folly/io/async:async_base",
        "@folly//folly/io/async:delayed_destruction",
        "@folly//folly/io/async:event_base_manager",
        "@folly//folly/portability:gflags",
    ],
)

cc_binary(
    name = "httpserver_samples_push",
    srcs = glob([
        "proxygen/httpserver/samples/push/*.cpp",
        "proxygen/httpserver/samples/push/*.h",
    ]),
    data = ["proxygen/httpserver/samples/push/pusheen.txt"],
    # NOTE: the binary is run from a sub-directory called "_main". Hence the "../".
    env = {"PUSH_FILE_NAME": "../$(rlocationpath proxygen/httpserver/samples/push/pusheen.txt)"},
    visibility = ["//visibility:public"],
    deps = [
        ":httpserver",
        "@folly//folly:file_util",
        "@folly//folly:memory",
        "@folly//folly/io/async:event_base_manager",
        "@folly//folly/portability:gflags",
        "@folly//folly/portability:unistd",
    ],
)

cc_binary(
    name = "httpserver_samples_static",
    srcs = glob([
        "proxygen/httpserver/samples/static/*.cpp",
        "proxygen/httpserver/samples/static/*.h",
    ]),
    visibility = ["//visibility:public"],
    deps = [
        ":httpserver",
        ":proxygen",
        "@folly//folly:file",
        "@folly//folly:file_util",
        "@folly//folly:memory",
        "@folly//folly/executors:cpu_thread_pool_executor",
        "@folly//folly/executors:global_executor",
        "@folly//folly/init",
        "@folly//folly/io/async:event_base_manager",
        "@folly//folly/portability:gflags",
        "@folly//folly/portability:unistd",
    ],
)

cc_binary(
    name = "httpserver_samples_websocket",
    srcs = glob([
        "proxygen/httpserver/samples/websocket/*.cpp",
        "proxygen/httpserver/samples/websocket/*.h",
    ]),
    visibility = ["//visibility:public"],
    deps = [
        ":httpserver",
        "@folly//folly:expected",
        "@folly//folly/executors:cpu_thread_pool_executor",
        "@folly//folly/executors:global_executor",
        "@folly//folly/init",
        "@folly//folly/io/async:event_base_manager",
    ],
)

###################################################################################################
# Tests
###################################################################################################

cc_library(
    name = "proxygen_test_main",
    srcs = ["proxygen/lib/test/TestMain.cpp"],
    visibility = ["//visibility:public"],
    deps = [
        "@folly//folly/portability:gflags",
        "@folly//folly/portability:gtest",
        "@glog",
    ],
)

cc_library(
    name = "proxygen_test_lib",
    srcs = glob(
        ["proxygen/lib/**/test/*.cpp"],
        exclude = [
            "proxygen/lib/dns/**",
            "proxygen/lib/stats/**",
            "proxygen/lib/test/TestMain.cpp",
            "proxygen/lib/**/test/*Bench.cpp",
            "proxygen/lib/**/test/*Benchmark.cpp",
            "proxygen/lib/**/test/*Test.cpp",
            "proxygen/lib/**/test/*Tests.cpp",
        ],
    ),
    hdrs = glob(
        ["proxygen/lib/**/test/*.h"],
        exclude = [
            "proxygen/lib/dns/**",
            "proxygen/lib/stats/**",
        ],
    ),
    visibility = ["//visibility:public"],
    deps = [
        ":proxygen",
        "@boost.optional",
        "@folly//folly:exception_wrapper",
        "@folly//folly:expected",
        "@folly//folly:format",
        "@folly//folly:function",
        "@folly//folly:memory",
        "@folly//folly:network_address",
        "@folly//folly:optional",
        "@folly//folly:random",
        "@folly//folly:string",
        "@folly//folly/futures:core",
        "@folly//folly/io:iobuf",
        "@folly//folly/io/async:async_base",
        "@folly//folly/io/async:async_socket_exception",
        "@folly//folly/io/async:async_transport",
        "@folly//folly/io/async:async_transport_certificate",
        "@folly//folly/io/async:event_base_manager",
        "@folly//folly/io/async/ssl:openssl_transport_certificate",
        "@folly//folly/io/async/test:mocks",
        "@folly//folly/json:dynamic",
        "@folly//folly/portability:gmock",
        "@folly//folly/portability:gtest",
        "@glog",
        "@googletest//:gtest",
        "@mvfst//:quic",
        "@mvfst//:quic_test_lib",
        "@wangle//:acceptor",
    ],
)

[cc_test(
    name = test_file.removesuffix(".cpp").replace("/", "_"),
    size = "small",
    srcs = [test_file],
    data = [
        # NOTE: These are used by proxygen/lib/http/session/test/HTTPSessionAcceptorTest.cpp, which
        # is disabled for now because I could not figure out how to make it find the runfiles.
        "proxygen/lib/http/session/test/test_cert1.key",
        "proxygen/lib/http/session/test/test_cert1.pem",
    ],
    local_defines = [
        # NOTE: the test is run from a sub-directory called "_main". Hence the "../".
        # The test looks at the parent dir of the given file.
        "BAZEL_TEST_RPATH='\"../$(rlocationpath proxygen/lib/http/session/test/test_cert1.pem)\"'",
    ],
    deps = [
        ":proxygen",
        ":proxygen_test_lib",
        ":proxygen_test_main",
        "@boost.algorithm",
        "@boost.container",
        "@boost.optional",
        "@fizz",
        "@folly//folly:base64",
        "@folly//folly:conv",
        "@folly//folly:expected",
        "@folly//folly:file_util",
        "@folly//folly:format",
        "@folly//folly:random",
        "@folly//folly:range",
        "@folly//folly:scope_guard",
        "@folly//folly:singleton",
        "@folly//folly:string",
        "@folly//folly/container:foreach",
        "@folly//folly/executors:io_thread_pool_executor",
        "@folly//folly/futures:core",
        "@folly//folly/io:iobuf",
        "@folly//folly/io/async:async_base",
        "@folly//folly/io/async:async_ssl_socket",
        "@folly//folly/io/async:event_base_manager",
        "@folly//folly/io/async:server_socket",
        "@folly//folly/io/async/test:mock_server_socket",
        "@folly//folly/io/async/test:mocks",
        "@folly//folly/io/async/test:util",
        "@folly//folly/logging",
        "@folly//folly/portability:gflags",
        "@folly//folly/portability:gmock",
        "@folly//folly/portability:gtest",
        "@folly//folly/synchronization:baton",
        "@glog",
        "@mvfst//:quic",
        "@wangle//:acceptor",
        "@wangle//:client_persistence_test_lib",
    ],
) for test_file in glob(
    [
        "proxygen/lib/**/test/*Test.cpp",
        "proxygen/lib/**/test/*Tests.cpp",
    ],
    exclude = [
        "proxygen/lib/dns/**",
        "proxygen/lib/stats/**",
        # This does not compile. It seems like an internal facebook file that escaped.
        "proxygen/lib/http/sink/test/HTTPConnectSinkTest.cpp",
        # This test is ignored by the CMakeLists.txt.
        "proxygen/lib/utils/test/URLTest.cpp",
        # The following 2 tests have their own separate cc_test below because they have to be linked
        # together in order to work.
        "proxygen/lib/http/codec/test/HTTP2CodecTest.cpp",
        "proxygen/lib/http/codec/test/HTTP2FramerTest.cpp",
        # TODO(kgk): Fix below tests.
        "proxygen/lib/utils/test/ParseURLTest.cpp",
    ],
)]

# These two tests have to be linked together in order to work.
cc_test(
    name = "proxygen_lib_http_test_HTTP2CodecTest_HTTP2FramerTest",
    size = "small",
    srcs = [
        "proxygen/lib/http/codec/test/HTTP2CodecTest.cpp",
        "proxygen/lib/http/codec/test/HTTP2FramerTest.cpp",
    ],
    deps = [
        ":proxygen",
        ":proxygen_test_lib",
        ":proxygen_test_main",
        "@folly//folly:random",
        "@folly//folly/io:iobuf",
        "@folly//folly/portability:gmock",
        "@folly//folly/portability:gtest",
    ],
)

cc_library(
    name = "httpserver_test_lib",
    hdrs = ["proxygen/httpserver/Mocks.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":httpserver",
        "@folly//folly/portability:gmock",
    ],
)

[cc_test(
    name = test_file.removesuffix(".cpp").replace("/", "_"),
    size = "small",
    srcs = [test_file],
    data = glob(
        ["proxygen/httpserver/tests/certs/*.pem"],
    ) + [
        "proxygen/httpserver/tests/CMakeLists.txt",
    ],
    # NOTE: the test is run from a sub-directory called "_main". Hence the "../".
    # The test looks at the parent dir of the given file.
    local_defines = [
        "BAZEL_TEST_RPATH='\"../$(rlocationpath proxygen/httpserver/tests/CMakeLists.txt)\"'",
    ],
    deps = [
        ":httpclient_samples_curl_lib",
        ":httpserver",
        ":httpserver_test_lib",
        ":proxygen",
        ":proxygen_test_lib",
        ":proxygen_test_main",
        "@boost.thread",
        "@folly//folly:file_util",
        "@folly//folly/executors:io_thread_pool_executor",
        "@folly//folly/io/async:async_ssl_socket",
        "@folly//folly/io/async:server_socket",
        "@folly//folly/logging",
        "@folly//folly/portability:gmock",
        "@folly//folly/portability:gtest",
        "@folly//folly/ssl:openssl_cert_utils",
        "@folly//folly/ssl:openssl_ptr_types",
        "@wangle//:acceptor",
        "@wangle//:client_ssl",
    ],
) for test_file in glob(["proxygen/httpserver/**/tests/*Test.cpp"])]
